#include <bits/stdc++.h>
using namespace std;

/*
s = v0*t+1/2*a*t*t
v = v0+a*t
v*v-v0*v0 = 2*a*s
*/

const int MAXN = 1e5+5;
const int MAXM = 1e6+5;
int T;
int n,m,L,V;

struct car
{
	int d,v,a;
	int st,ed;
}c[MAXN];

int p[MAXN];
int add[MAXN];  //from i~m,+add[i]
int mi[MAXN];
bool flag[MAXN];

inline void solve1()
{
	for(int i=1;i<=n;++i)
	{
		if(c[i].a==0 && c[i].v<=V)continue;
		if(c[i].a>0)
		{
			int len;
			if(c[i].a==0 && c[i].v>V)
				len = c[i].d;
			else
			{
				double t = (1ll*V*V-1ll*c[i].v*c[i].v)*1.0/2/c[i].a;
				if(t-(int)t<=0.000001)
					len = (int)t+1;
				else
					len = ceil(t);
			}
			int pos = lower_bound(p+1,p+m+1,c[i].d+len)-p;
			if(pos<=m)
			{
				c[i].st = pos;
				add[pos]++;
				flag[i] = 1;
			}
		}
		else if(c[i].a<0 && c[i].v>=V)
		{
			int pos = lower_bound(p+1,p+m+1,c[i].d)-p;
			int len = p[pos]-c[i].d;
			double v = sqrt(1ll*c[i].v*c[i].v-2ll*c[i].a*len);
			if(v>V)
			{
				c[i].st = pos;
				add[pos]++;
				flag[i] = 1;
			}
		}
	}
	for(int i=1;i<=n;++i)
	{
		if(c[i].a>=0 || !flag[i])continue;
		int len;
		double t = (0ll-1ll*c[i].v*c[i].v)*1.0/2/c[i].a;
		if(t-(int)t<=0.000001)
			len = (int)t+1;
		else
			len = ceil(t);
		int pos = lower_bound(p+1,p+m+1,c[i].d+len)-p;
		if(pos<=m)
		{
			mi[pos]++;
			c[i].ed = pos;
		}
	}
	int res = 0;
	for(int i=1;i<=m;++i)
		res += add[i];
	printf("%d ",res);
}

set<int> st;

inline void solve2()
{
	int ans = 1;
	for(int i=1;i<=n;++i)
	{
		for(int j=c[i].st;j<=c[i].ed;++j)
			st.insert(j);
	}
	set<int>::iterator it = st.begin();
	int last = *it;
	for(;it!=st.end();++it)
	{
		if(*it!=last+1)
			ans += 2;
		last = *it;
	}
	printf("%d\n",max(ans,m-ans));
}

inline void solve()
{
	memset(c,0,sizeof(c));
	memset(p,0,sizeof(p));
	memset(add,0,sizeof(add));
	scanf("%d%d%d%d",&n,&m,&L,&V);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d%d",&c[i].d,&c[i].v,&c[i].a);
		c[i].ed = m;
	}
	for(int i=1;i<=m;++i)
		scanf("%d",&p[i]);
	sort(p+1,p+m+1);
	solve1();
	solve2();
}

int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	scanf("%d",&T);
	while(T--)
		solve();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
